package de.andreavicentini.teatralia.generate;

import org.magiclabs.htmlx.*;
import de.andreavicentini.teatralia.pages.repertoire.*;
import de.andreavicentini.teatralia.pages.*;

public class Repertoire implements ITransfx {
  protected static String nl;
  public static synchronized Repertoire create(String lineSeparator)
  {
    nl = lineSeparator;
    Repertoire result = new Repertoire();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "";
  protected final String TEXT_2 = NL + NL + "<p class=\"intro\">";
  protected final String TEXT_3 = "</p>" + NL + "" + NL + "<h2>";
  protected final String TEXT_4 = "</h2>" + NL;
  protected final String TEXT_5 = NL + NL + "<a name=\"";
  protected final String TEXT_6 = "\">";
  protected final String TEXT_7 = NL;
  protected final String TEXT_8 = NL + "<p>";
  protected final String TEXT_9 = NL + NL + "<h2>";
  protected final String TEXT_10 = "</h2>" + NL;
  protected final String TEXT_11 = NL + "<a name=\"";
  protected final String TEXT_12 = "\">";
  protected final String TEXT_13 = NL;
  protected final String TEXT_14 = " " + NL + "<p>";
  protected final String TEXT_15 = "</p>" + NL + "</div><p>" + NL;

	public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(TEXT_1);
      
RepertoirePage page = (RepertoirePage) argument;

    stringBuffer.append(TEXT_2);
    stringBuffer.append( page.getText(RepertoirePage.Keys.intro) );
    stringBuffer.append(TEXT_3);
    stringBuffer.append( page.getText(RepertoirePage.Keys.title_plays) );
    stringBuffer.append(TEXT_4);
     for (IPlay play : page.iteratePlays()) {  
    stringBuffer.append(TEXT_5);
    stringBuffer.append( play.hashCode() );
    stringBuffer.append(TEXT_6);
    stringBuffer.append(TEXT_7);
    stringBuffer.append( play.getRenderer().generate(page, play) );
    stringBuffer.append(TEXT_8);
     } 
    stringBuffer.append(TEXT_9);
    stringBuffer.append( page.getText(RepertoirePage.Keys.title_authors) );
    stringBuffer.append(TEXT_10);
     for (Author author : page.iterateAuthors()) { 
    stringBuffer.append(TEXT_11);
    stringBuffer.append( author.getLastName() );
    stringBuffer.append(TEXT_12);
    stringBuffer.append(TEXT_13);
    stringBuffer.append( new ToggleHeader(author.getLastName(), author.toString() + " <span class=\"secondline\">(" + author.getCity() + ", " + author.getBirthDate() + " &mdash; " + author.getCityDeath() + ", " + author.getDeath() + ")</span>") );
    stringBuffer.append(TEXT_14);
    stringBuffer.append( page.getText(author.getDescription()) );
    stringBuffer.append(TEXT_15);
     } 
    return stringBuffer.toString();
  }
}